<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/24 0024
 * Time: 16:19
 */

namespace app\common\traits;

use Overtrue\EasySms\EasySms;

/**
 * Trait Sms
 * @package app\common\traits
 * @author: Huang
 */
trait Sms
{
    public static $config = [
        // HTTP 请求的超时时间（秒）
        'timeout' => 5.0,

        // 默认发送配置
        'default' => [
            // 网关调用策略，默认：顺序调用
            'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,

            // 默认可用的发送网关
            'gateways' => [
                'aliyun'
            ]
        ],
        // 可用的网关配置
        'gateways' => [
            'errorlog' => [
                'file' => '/tmp/easy-sms.log',
            ],
            'aliyun' => [
                'access_key_id' => 'LTAIek9HQOBWTg5d',
                'access_key_secret' => 'XrKWhbEPKcZeOEj8QQPqWwgL1sV0Ko',
                'sign_name' => '重庆纷乐迪儿童摄影',
            ],
            'yunpian' => [
                'api_key' => '824f0ff2f71cab52936axxxxxxxxxx',
            ],
            'alidayu' => [
                //...
            ],
        ],
    ];
    public static $smsapp = null;

    /**
     * 短信发送
     * @return Application|null
     * @author: Huang
     * @internal
     */
    static public function getSmsInstance()
    {
        if (is_null(self::$smsapp) || isset (self::$smsapp)) {
            if (!empty($config)) self::$options = array_merge(self::$options, json_decode($config, true));
            self::$smsapp = new EasySms(self::$config);
        }
        return self::$smsapp;
    }
}